package com.sdry.web.controller.hpf;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sdry.model.hpf.Position;
import com.sdry.model.hpf.Product;
import com.sdry.model.jyy.Shedudetail;
import com.sdry.model.llm.Classes;
import com.sdry.model.llm.Team;
import com.sdry.service.hpf.AllReportService;
import com.sdry.service.hpf.PickApplyService;
import com.sdry.service.hpf.PositionService;
import com.sdry.service.hpf.ProductService;
import com.sdry.service.llm.ClassesService;
import com.sdry.service.llm.TeamService;


/**
 * @ClassName: MyMenuController 
 * @Description:进入菜单Controller
 * @Author hpf
 * @Date 2018年9月12日 上午10:52:01 
 * @version 1.0
 */
@Controller
@RequestMapping(value="/stockMenu")
public class MyMenuController {

	@Resource
	private AllReportService allReportService;
	@Resource
	private PickApplyService pickApplyService;
	@Resource
	private TeamService teamService;
	@Resource
	private PositionService positionService;
	@Resource
	private ProductService productService;
	@Resource
	private ClassesService classesService;
	
	
	/**
	 * 进入库存列表页面
	 * @return
	 */
	@RequestMapping(value="/toStockListPage")
	public String toStockListPage(){
		return "/hpf/stockManaList";
	}
	
	/**
	 * 进入产品入库列表页面
	 * @return
	 */
	@RequestMapping(value="/toProductWarehouseListPage")
	public String toProductWarehouseListPage(){
		return "/hpf/productWarehouseList";
	}
	
	/**
	 * 进入产品出库列表页面
	 * @return
	 */
	@RequestMapping(value="/toProductOutListPage")
	public String toProductOutListPage(){
		return "/hpf/productOutList";
	}
	
	/**
	 * 进入物料库存列表页面
	 * @return
	 */
	@RequestMapping(value="/toMaterialStockListPage")
	public String toMaterialStockListPage(){
		return "/hpf/materialStockList";
	}
	/**
	 * 进入物料入库列表页面
	 * @return
	 */
	@RequestMapping(value="/toMaterialWarehouseListPage")
	public String toMaterialWarehouseListPage(){
		return "/hpf/materialWarehouseList";
	}
	/**
	 * 进入物料出库列表页面
	 * @return
	 */
	@RequestMapping(value="/toMaterialOutListPage")
	public String toMaterialOutListPage(){
		return "/hpf/materialOutList";
	}
	/**
	 * 进入物料退库列表页面
	 * @return
	 */
	@RequestMapping(value="/toMaterialReturnListPage")
	public String toMaterialReturnListPage(){
		return "/hpf/materialReturnList";
	}
	/**
	 * 进入线边库页面
	 * @return
	 */
	@RequestMapping(value="/toLineSideLibraryListPage")
	public ModelAndView toLineSideLibraryListPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/lineSideLibraryList");
		return mv;
	}
	
	/**
	 * 进入缓存区页面
	 * @return
	 */
	@RequestMapping(value="/toCacheAreaListPage")
	public ModelAndView toCacheAreaListPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/cacheAreaList");
		return mv;
	}
/**
	 * 进入领料申请单列表页面
	 * @return
	 */
	@RequestMapping(value="/toPickApplyListPage")
	public ModelAndView toPickApplyListPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/pickApplyList");
		return mv;
	}
	
	/**
	 * 进入生产记录报表
	 * @return
	 */
	@RequestMapping(value="/toProductRecordPage")
	public ModelAndView toProductRecordPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/productRecord");
		return mv;
	}
	
	/**
	 * 进入生产记录报表
	 * @return
	 */
	@RequestMapping(value="/toProductStatusPage")
	public ModelAndView toProductStatusPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/productStatus");
		return mv;
	}
	
	/**
	 * 进入线边库盘点
	 * @return
	 */
	@RequestMapping(value="/toLineSideLibraryCheckPage")
	public ModelAndView toLineSideLibraryCheckPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/lineSideLibraryCheck");
		return mv;
	}
	
	/**
	 * 进入缓存区盘点
	 * @return
	 */
	@RequestMapping(value="/toCacheAreaCheckPage")
	public ModelAndView toCacheAreaCheckPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/cacheAreaCheck");
		return mv;
	}
	
	/**
	 * 进入审批待办
	 * @return
	 */
	@RequestMapping(value="/toApprovalPendPage")
	public ModelAndView toApprovalPendPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/approvalPend");
		return mv;
	}
	
	/**
	 * 进入审批已办
	 * @return
	 */
	@RequestMapping(value="/toApprovalCompletePage")
	public ModelAndView toApprovalCompletePage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/approvalComplete");
		return mv;
	}
	
	/**
	 * 产量统计表
	 * @return
	 */
	@RequestMapping(value="/toProductionStatisticsPage")
	public ModelAndView toProductionStatisticsPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/productionStatistics");
		return mv;
	}
	
	/**
	 * 线边库入库管理页面
	 * @return
	 */
	@RequestMapping(value="/toLineSideLibraryInListPage")
	public ModelAndView toLineSideLibraryInPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/lineSideLibraryInList");
		return mv;
	}
	
	/**
	 * 线边库出库管理页面
	 * @return
	 */
	@RequestMapping(value="/toLineSideLibraryOutListPage")
	public ModelAndView toLineSideLibraryOutPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/lineSideLibraryOutList");
		return mv;
	}
	
	/**
	 * 缓存区入库管理页面
	 * @return
	 */
	@RequestMapping(value="/toCacheAreaInListPage")
	public ModelAndView toCacheAreaInListPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/cacheAreaInList");
		return mv;
	}
	
	/**
	 * 缓存区出库管理页面
	 * @return
	 */
	@RequestMapping(value="/toCacheAreaOutListPage")
	public ModelAndView toCacheAreaOutListPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/cacheAreaOutList");
		return mv;
	}
	
	/**
	 * 设备台账报表页面
	 * @return
	 */
	@RequestMapping(value="/toDeviceAccountPage")
	public ModelAndView toDeviceAccountPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/deviceAccount");
		return mv;
	}
	
	/**
	 * 设备档案报表页面
	 * @return
	 */
	@RequestMapping(value="/toDeviceFilePage")
	public ModelAndView toDeviceFilePage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/deviceFile");
		return mv;
	}
	
	/**
	 * 设备保养计划报表页面
	 * @return
	 */
	@RequestMapping(value="/toMaintenanceResume2Page")
	public ModelAndView toMaintenanceResume2Page(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/maintenanceResume2");
		return mv;
	}
	
	/**
	 * 设备巡检报表页面
	 * @return
	 */
	@RequestMapping(value="/toDeviceCheckFormPage")
	public ModelAndView toDeviceCheckFormPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/deviceCheckForm");
		return mv;
	}
	
	/**
	 * 湿法（热法）膜纺丝记录报表页面
	 * @return
	 */
	@RequestMapping(value="/toProductInspectPage")
	public ModelAndView toProductInspectPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/productInspect");
		return mv;
	}
	
	/**
	 * 用料记录报表页面
	 * @return
	 */
	@RequestMapping(value="/toMaterialRecordPage")
	public ModelAndView toMaterialRecordPage(){
		ModelAndView mv = new ModelAndView();
		List<Team> tList = teamService.listAllTeam();
		mv.addObject("tList", tList);
		mv.setViewName("/hpf/materialRecord");
		return mv;
	}
	
	/**
	 * 膜丝生产线看板页面
	 * @return
	 */
	@RequestMapping(value="/toMembraneBoardPage")
	public ModelAndView toMembraneBoardPage(){
		ModelAndView mv = new ModelAndView();
		List<Product> pList = productService.listAllProduct(new Product());
		int c0960_mNum = 0;
		int c1060_mNum = 0;
		int c0980_mNum = 0;
		int c1080_mNum = 0;
		for (int i = 0; i < pList.size(); i++) {
			if ("PSH2-0960-T-01".equals(pList.get(i).getPnum())) {
				c0960_mNum = Integer.parseInt(pList.get(i).getClassify());
			}
			if ("PSH1-1060-B-03".equals(pList.get(i).getPnum())) {
				c1060_mNum = Integer.parseInt(pList.get(i).getClassify());
			}
			if ("PSH2-0980-T-02".equals(pList.get(i).getPnum())) {
				c0980_mNum = Integer.parseInt(pList.get(i).getClassify());
			}
			if ("PSH1-1080-C-04".equals(pList.get(i).getPnum())) {
				c1080_mNum = Integer.parseInt(pList.get(i).getClassify());
			}
		}
		mv.addObject("c0960_mNum", c0960_mNum);
		mv.addObject("c1060_mNum", c1060_mNum);
		mv.addObject("c0980_mNum", c0980_mNum);
		mv.addObject("c1080_mNum", c1080_mNum);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
		Date d  = new Date();
		String time = sdf.format(d);
		String today = sdfDay.format(d);
		String startTime = "";
		String endTime = "";
		String planTime = "";
		//当天的小时
		Integer hourse = Integer.parseInt(time.substring(11, 13));
		//如果登录时间小于当天的白班的开始时间，则记录上一天
		if(hourse < 7){
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
			ca.setTime(d); //设置时间为当前时间
			ca.add(Calendar.DATE, -1);
			Date last = ca.getTime();
			String lastTime = sdfDay.format(last);
			startTime = lastTime;
			endTime = today;
			planTime = lastTime;
		}else{
			//查询下一天的日期
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
			ca.setTime(d); //设置时间为当前时间
			ca.add(Calendar.DATE, +1);
			Date next = ca.getTime();
			String nextTime = sdfDay.format(next);
			startTime = today;
			endTime = nextTime;
			planTime = today;
		}
		//白班的开始时间
		List<Classes> classesByName = classesService.getClassesByName("白班");
		Classes cla = classesByName.get(0);
		String hh = cla.getStartTime();
		Map<String, Object> map1 = new HashMap<>();
		Map<String, Object> map2 = new HashMap<>();
		Map<String, Object> map3 = new HashMap<>();
		Map<String, Object> map4 = new HashMap<>();
		Map<String, Object> map5 = new HashMap<>();
		Map<String, Object> map6 = new HashMap<>();
		Map<String, Object> map7 = new HashMap<>();
		Map<String, Object> map8 = new HashMap<>();
		Map<String, Object> map9 = new HashMap<>();
		Map<String, Object> map10 = new HashMap<>();
		Map<String, Object> map11 = new HashMap<>();
		Map<String, Object> map12 = new HashMap<>();
		map1.put("beginTime", startTime + " " + hh);
		map1.put("endTime", endTime + " " + hh);
		map1.put("line", "01");
		map1.put("product", "01");
		map2.put("beginTime", startTime + " " + hh);
		map2.put("endTime", endTime + " " + hh);
		map2.put("line", "01");
		map2.put("product", "02");
		map3.put("beginTime", startTime + " " + hh);
		map3.put("endTime", endTime + " " + hh);
		map3.put("line", "02");
		map3.put("product", "01");
		map4.put("beginTime", startTime + " " + hh);
		map4.put("endTime", endTime + " " + hh);
		map4.put("line", "02");
		map4.put("product", "02");
		map5.put("beginTime", startTime + " " + hh);
		map5.put("endTime", endTime + " " + hh);
		map5.put("line", "03");
		map5.put("product", "01");
		map6.put("beginTime", startTime + " " + hh);
		map6.put("endTime", endTime + " " + hh);
		map6.put("line", "03");
		map6.put("product", "02");
		map7.put("beginTime", startTime + " " + hh);
		map7.put("endTime", endTime + " " + hh);
		map7.put("line", "04");
		map7.put("product", "01");
		map8.put("beginTime", startTime + " " + hh);
		map8.put("endTime", endTime + " " + hh);
		map8.put("line", "04");
		map8.put("product", "02");
		map9.put("beginTime", startTime + " " + hh);
		map9.put("endTime", endTime + " " + hh);
		map9.put("line", "05");
		map9.put("product", "03");
		map10.put("beginTime", startTime + " " + hh);
		map10.put("endTime", endTime + " " + hh);
		map10.put("line", "05");
		map10.put("product", "04");
		map11.put("beginTime", startTime + " " + hh);
		map11.put("endTime", endTime + " " + hh);
		map11.put("line", "06");
		map11.put("product", "03");
		map12.put("beginTime", startTime + " " + hh);
		map12.put("endTime", endTime + " " + hh);
		map12.put("line", "06");
		map12.put("product", "04");
		int h11 = allReportService.selectMSQuantity(map1);
		int h12 = allReportService.selectMSQuantity(map2);
		int h21 = allReportService.selectMSQuantity(map3);
		int h22 = allReportService.selectMSQuantity(map4);
		int h31 = allReportService.selectMSQuantity(map5);
		int h32 = allReportService.selectMSQuantity(map6);
		int h41 = allReportService.selectMSQuantity(map7);
		int h42 = allReportService.selectMSQuantity(map8);
		int w13 = allReportService.selectMSQuantity(map9);
		int w14 = allReportService.selectMSQuantity(map10);
		int w23 = allReportService.selectMSQuantity(map11);
		int w24 = allReportService.selectMSQuantity(map12);
		mv.addObject("h11", h11);
		mv.addObject("h12", h12);
		mv.addObject("h21", h21);
		mv.addObject("h22", h22);
		mv.addObject("h31", h31);
		mv.addObject("h32", h32);
		mv.addObject("h41", h41);
		mv.addObject("h42", h42);
		mv.addObject("w13", w13);
		mv.addObject("w14", w14);
		mv.addObject("w23", w23);
		mv.addObject("w24", w24);
		int c0960_1 = 0;
		int c0980_1 = 0;
		int c0960_2 = 0;
		int c0980_2 = 0;
		int c0960_3 = 0;
		int c0980_3 = 0;
		int c0960_4 = 0;
		int c0980_4 = 0;
		int c1060_1 = 0;
		int c1080_1 = 0;
		int c1060_2 = 0;
		int c1080_2 = 0;
		Shedudetail shedudetail =pickApplyService.findShedudetailByDate(planTime);
		if (null != shedudetail) {
			/*热法4条线计划数量*/
			String c09601 = shedudetail.getC09601();//热法1号线0960 个数
			String c09801 = shedudetail.getC09801();//热法1号线0980 个数
			String c09602 = shedudetail.getC09602();//热法2号线0960 个数
			String c09802 = shedudetail.getC09802();//热法2号线0980 个数
			String c09603 = shedudetail.getC09603();//热法3号线0960 个数
			String c09803 = shedudetail.getC09803();//热法3号线0980 个数
			String c09604 = shedudetail.getC09604();//热法4号线0960 个数
			String c09804 = shedudetail.getC09804();//热法4号线0980 个数
			/*湿法2条线计划数量*/
			String c10601 = shedudetail.getC10601();//湿法1号线1060 个数
			String c10801 = shedudetail.getC10801();//湿法1号线1080 个数
			String c10602 = shedudetail.getC10602();//湿法2号线1060 个数
			String c10802 = shedudetail.getC10802();//湿法2号线1080 个数
			if ("".equals(c09601) || c09601 == null) {
				c0960_1 = 0;
			} else {
				c0960_1 = Integer.parseInt(c09601);
			}
			if ("".equals(c09801) || c09801 == null) {
				c0980_1 = 0;
			} else {
				c0980_1 = Integer.parseInt(c09801);
			}
			if ("".equals(c09602) || c09602 == null) {
				c0960_2 = 0;
			} else {
				c0960_2 = Integer.parseInt(c09602);
			}
			if ("".equals(c09802) || c09802 == null) {
				c0980_2 = 0;
			} else {
				c0980_2 = Integer.parseInt(c09802);
			}
			if ("".equals(c09603) || c09603 == null) {
				c0960_3 = 0;
			} else {
				c0960_3 = Integer.parseInt(c09603);
			}
			if ("".equals(c09803) || c09803 == null) {
				c0980_3 = 0;
			} else {
				c0980_3 = Integer.parseInt(c09803);
			}
			if ("".equals(c09604) || c09604 == null) {
				c0960_4 = 0;
			} else {
				c0960_4 = Integer.parseInt(c09604);
			}
			if ("".equals(c09804) || c09804 == null) {
				c0980_4 = 0;
			} else {
				c0980_4 = Integer.parseInt(c09804);
			}
			if ("".equals(c10601) || c10601 == null) {
				c1060_1 = 0;
			} else {
				c1060_1 = Integer.parseInt(c10601);
			}
			if ("".equals(c10801) || c10801 == null) {
				c1080_1 = 0;
			} else {
				c1080_1 = Integer.parseInt(c10801);
			}
			if ("".equals(c10602) || c10602 == null) {
				c1060_2 = 0;
			} else {
				c1060_2 = Integer.parseInt(c10602);
			}
			if ("".equals(c10802) || c10802 == null) {
				c1080_2 = 0;
			} else {
				c1080_2 = Integer.parseInt(c10802);
			}
		}
		mv.addObject("c0960_1", c0960_1);
		mv.addObject("c0980_1", c0980_1);
		mv.addObject("c0960_2", c0960_2);
		mv.addObject("c0980_2", c0980_2);
		mv.addObject("c0960_3", c0960_3);
		mv.addObject("c0980_3", c0980_3);
		mv.addObject("c0960_4", c0960_4);
		mv.addObject("c0980_4", c0980_4);
		mv.addObject("c1060_1", c1060_1);
		mv.addObject("c1080_1", c1080_1);
		mv.addObject("c1060_2", c1060_2);
		mv.addObject("c1080_2", c1080_2);
		mv.setViewName("/hpf/membraneBoard");
		return mv;
	}
	
	/**
	 * 成品库管理页面
	 * @return
	 */
	@RequestMapping(value="/toFinishProductLibraryPage")
	public ModelAndView toFinishProductLibraryPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/finishProductLibraryList");
		return mv;
	}
	
	/**
	 * 成品库入库管理页面
	 * @return
	 */
	@RequestMapping(value="/toFinishProductLibraryInPage")
	public ModelAndView toFinishProductLibraryInPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/finishProductLibraryInList");
		return mv;
	}
	
	/**
	 * 成品库出库管理页面
	 * @return
	 */
	@RequestMapping(value="/toFinishProductLibraryOutPage")
	public ModelAndView toFinishProductLibraryOutPage(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/hpf/finishProductLibraryOutList");
		return mv;
	}
	
	/**
	 * 工艺通知单页面
	 * @return
	 */
	@RequestMapping(value="/toChangeNoticePage")
	public ModelAndView toChangeNoticePage(){
		ModelAndView mv = new ModelAndView();
		List<Position> pList = positionService.listAllPosition();
		mv.addObject("pList", pList);
		mv.setViewName("/hpf/changeNoticeList");
		return mv;
	}
}
